<?php

namespace App\Http\Resources\Kms\App;

use App\Service\Kms\Common\FeishuService;
use Illuminate\Http\Resources\Json\JsonResource;

class ClientsListResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            "id"                    => (int)$this->id,
            "icon"                  => (string)$this->icon,
            "name"                  => (string)$this->name,
            "desc"                  => (string)$this->desc,
            "sort"                  => (int)$this->sort,
            "type"                  => (int)$this->type,
            "childType"             => (int)$this->childType,
            "uniAppId"              => (string)$this->uniAppId,
            "clientId"              => (int)$this->clientId,
            "status"                => (int)$this->status,
            "clientsVersionLastRel" => AppVersionListResource::collection($this->clientsVersionRel ? [$this->clientsVersionRel] : [])
                                                             ->getIterator()->current()
        ]; // TODO=> Change the autogenerated stub
    }

    public static function formatData($item)
    {
        return [
            "id"                    => (int)$item->id,
            "icon"                  => (string)$item->icon,
            "name"                  => (string)$item->name,
            "desc"                  => (string)$item->desc,
            "sort"                  => (int)$item->sort,
            "type"                  => (int)$item->type,
            "childType"             => (int)$item->childType,
            "uniAppId"              => (string)$item->uniAppId,
            "clientId"              => (int)$item->clientId,
            "status"                => (int)$item->status,
            "clientsVersionLastRel" => AppVersionListResource::collection($item->clientsVersionRel ? [$item->clientsVersionRel] : [])
                                                             ->getIterator()->current()
        ]; // TODO=> Change the autogenerated stub
    }
}
